/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { ParserOptions } from './options';
import { Parser } from './parser';
import { airBlob } from './test_blob/air-blob';
import { babylonBlob } from './test_blob/babylon-blob';
import { inspectorBlob } from './test_blob/inspector-blob';
import { basicBlob } from './test_blob/basic-blob';

const ONE_THOUSAND: number = 1000;
const LOOP_COUNT: number = 1;

export class BabylonBenchmark {
  allSourceCode = [airBlob, babylonBlob, inspectorBlob, basicBlob];

  run(): void {
    let i = 0;
    for (let source of this.allSourceCode) {
      let options = new ParserOptions();
      if (i === 1) {
        options.sourceType = 'module';
      }
      let parser = new Parser(options, source);
      let node = parser.parse();
      i++;
    }
  }

  runIteration(): void {
    let startTime = ArkTools.timeInUs() / ONE_THOUSAND;
    // let startTime = Date.now();
    for (let i = 0; i < LOOP_COUNT; i++) {
      this.run();
    }
    let endTime = ArkTools.timeInUs() / ONE_THOUSAND;
    // let endTime = Date.now();
    print(`Babylon: ms = ${endTime - startTime}`);
    // console.log(`Babylon: ms = ${endTime - startTime}`);
  }
}

declare interface ArkTools {
  timeInUs(args: number): number;
}

new BabylonBenchmark().runIteration();